<?php defined('SYSPATH') or die('No direct script access.');
/**
 * @author : thanh.dang
 * @version: 1.0
 */
class CustomPagerLayout extends Doctrine_Pager_Layout
{
    public function display($options = array(), $return = false) {
    	
        $pager = $this->getPager();
        
        $str = '<div class="pagination">';
        
        if($pager->getPage() != 1)
        {
            // First page
            $this->addMaskReplacement('page', '&laquo;', true);
            $options['page_number'] = $pager->getFirstPage();
            $str .= $this->processPage($options);
        }
        
        if($pager->getPage() > 1)
        {
            // Previous page
            $this->addMaskReplacement('page', '&lsaquo;', true);
            $options['page_number'] = $pager->getPreviousPage();
            $str .= $this->processPage($options);
        }
        // Pages listing
        $this->removeMaskReplacement('page');
        $str .= parent::display($options, true);
        
        
        // Next page
        if($pager->getPage() < $pager->getLastPage())
        {
            $this->addMaskReplacement('page', '&rsaquo;', true);
            $options['page_number'] = $pager->getNextPage();
            $str .= $this->processPage($options);
        }
        
        if($pager->getPage() != $pager->getLastPage())
        {
            // Last page
            $this->addMaskReplacement('page', '&raquo;', true);
            $options['page_number'] = $pager->getLastPage();
            $str .= $this->processPage($options);
        }
        
        $str .= '</div>';
        
        // Possible wish to return value instead of print it on screen
        if ($return) {
            return $str;
        }

        echo $str;
    }
}